Skip to content

C++: Split new range analysis into constant and relative stages#11928

Merged
MathiasVP merged 10 commits intogithub:mainfrom
rdmarsh2:rdmarsh2/stageify-range-analysis
Mar 18, 2023
Merged

C++: Split new range analysis into constant and relative stages#11928
MathiasVP merged 10 commits intogithub:mainfrom
rdmarsh2:rdmarsh2/stageify-range-analysis

Conversation

@rdmarsh2
Copy link
Copy Markdown
Contributor

This splits the new range analysis into a constant stage and a relative stage, so that the constant stage can be used for overflow detection and potentially include some nonlinear recursion, while limiting the total performance impact by keeping relative bounds out of that recursion.

@rdmarsh2 rdmarsh2 requested a review from a team as a code owner January 18, 2023 20:30
@github-actions github-actions Bot added the C++ label Jan 18, 2023
@MathiasVP
Copy link
Copy Markdown
Contributor

I see there are some result changes caused by this PR. That's not expected, is it?

@rdmarsh2 rdmarsh2 force-pushed the rdmarsh2/stageify-range-analysis branch from 7e363fa to d4e3f7f Compare March 10, 2023 19:23
Copy link
Copy Markdown
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments. Mostly about keeping the files language-neutral

Comment thread cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticBound.qll Outdated
Comment on lines +6 to +7
private import semmle.code.cpp.ir.IR as IR
private import semmle.code.cpp.Location // TODO: SemLocation?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also the only language-specific parts of this file, right? I think we should move it out. As far as I can see, the only place where IR is used is in

this.(SemanticBound::SemSsaBound).getExpr(0) instanceof IR::PhiInstruction

which I hope we can refactor 🤞.

Comment on lines +47 to +51
private module ConstantStage =
RangeStage<FloatDelta, ConstantBounds, CppLangImpl, RangeUtil<FloatDelta, CppLangImpl>>;

private module RelativeStage =
RangeStage<FloatDelta, RelativeBounds, CppLangImpl, RangeUtil<FloatDelta, CppLangImpl>>;
Copy link
Copy Markdown
Contributor

@MathiasVP MathiasVP Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to check the performance impact of instantiating RangeStage twice. You can do that in one of two ways, I'd say:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty of starting option two here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DCA looks fine 🎉

Comment thread cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/RangeAnalysisStage.qll Outdated
@MathiasVP
Copy link
Copy Markdown
Contributor

Also seeing compilation failures on CI:

FAILED(COMPILATION) /home/runner/work/semmle-code/semmle-code/ql/cpp/ql/test/library-tests/ir/modulus-analysis/ModulusAnalysis.ql

MathiasVP
MathiasVP previously approved these changes Mar 17, 2023
Copy link
Copy Markdown
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment. Otherwise, this LGTM once DCA is happy

Edit: DCA finished and shows no new performance concerns. So my only two requests are:

  • Remove the unnecessary TODO comment, and
  • Get rid of the one IR-specific construct that's now used directly in RangeAnalysisImpl.qll.

Comment thread cpp/ql/lib/experimental/semmle/code/cpp/semantic/SemanticBound.qll Outdated
Comment thread cpp/ql/lib/experimental/semmle/code/cpp/semantic/analysis/RangeAnalysisImpl.qll Outdated
Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
@MathiasVP MathiasVP merged commit b0f8037 into github:main Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants